<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  backoffice
 */

/**
 * Get a media from medias folder in a module folder
 */
function smarty_function_moduleMedia($params, &$smarty)
{ 
	if(isset($params['module']) && isset($params['media']))
    {
        $route = f_core_Routing::getUrl('moduleMedia', array('moduleName' => $params['module'], 'mediaName' => $params['media']));
        $src = URL_RELATIVE.'/bo'.$route;

        if(isset($params['onlyUrl'])) return $src;

        $result = '<img src="'.$src.'" ';

        if(count($params) > 2)
        {
            foreach($params as $paramName => $value)
            {
                if($paramName != 'module' && $paramName != 'media')
                {
                    $result .= $paramName.'="'.$value.'" ';
                }
            }
        }

        $result .= '/>';
        return $result;
    }
	
	return '';
}